<html>
    <head>
        <title>视频列表</title>
        <meta charset="utf-8">
    </head>
    <body>
<?php
include_once("conn.php");
$sql_total="select count(*) from video where is_del = 1";
$query0 = mysqli_query($conn,$sql_total);
while($row0 = mysqli_fetch_array($query0)){
    $total = $row0[0];
}
$total_pages = ceil($total / 10);
$page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = 10; // 每页显示的数量
$offset = ($page - 1) * $limit;
$sql="select * from video where is_del = 1 order by name desc limit 10 offset ".$offset;

$query = mysqli_query($conn,$sql);
    while($row = mysqli_fetch_array($query)){    
        $id = $row['id']; 
?>
        <h1><?php echo $row['name'];?></h1>
        <div>
            <video width="320" height="240" controls>
            <source src="<?php echo $row['url'];?>" type="video/mp4">
            </video>
            <form method="POST" action="edit.php">
                <input type="hidden" name="del" value="<?php echo $row['id'];?>" >
                <button type="submit">详情</button>
            </form>
            <form method="POST" action="video.php">
                <input type="hidden" name="del" value="<?php echo $row['id'];?>" >
                <button type="submit">删除</button>
            </form>
        </div>
<?php
    }
    // 显示分页链接
    for ($i = 1; $i <= $total_pages; $i++) {
        echo '<a href="?page=' . $i . '">' . $i . '</a> ';
    }
    
    // 删除
    if($_POST['del']){
        $id = $_POST['del'];
        $sql1 = "UPDATE video SET is_del = 0 WHERE id = ".$id;
        $query = mysqli_query($conn,$sql1);
        header('Refresh:0');
    }
?>      
    </body>
</html>
